package morning.cat.springboot.demo.listener;

import morning.cat.springboot.demo.event.HelloApplicationEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @describe: 注解方式监听事件
 * @author: morningcat.zhang
 * @date: 2019/3/4 2:25 PM
 */
@Component
public class DemoEventListener {

    /**
     * 监听器
     *
     * @param event
     */
    @Async
    @EventListener
    public void listenerHelloApplicationEvent(HelloApplicationEvent event) {
        String param = event.getParam();
        System.out.println("-------111-------" + param);
    }

    /**
     * 两个监听器可以对同一个事件进行监听
     *
     * @param event
     */
    @Async
    @EventListener
    public void listenerHelloApplicationEvent2(HelloApplicationEvent event) {
        String param = event.getParam();
        System.out.println("-------222-------" + param);
    }


}
